package web;

import java.rmi.RemoteException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import auth.service.User;

public class AccueilController implements Controller{

	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		ModelAndView modelAndView =new ModelAndView("accueil");
		 HttpSession session = request.getSession();
		    synchronized (session) {
		        Object o = session.getAttribute("user");
		        if (o instanceof User) {
		            session.setAttribute("user", (User)o) ;
		        }else{
		        User user;
				try {
					user = new User();
					user.setAuth(0);
					session.setAttribute("user", user);
					
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		        }
		    }
		
		
		
		User user = (User) request.getSession().getAttribute("user");
		modelAndView.addObject("user", user);
		
		
		return modelAndView;
	}

}
